import java.awt.Color;
import java.awt.Cursor;
import java.awt.DisplayMode;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class BrickBreaker extends JFrame implements KeyListener
{

	private class BrickBreakerPanel extends JPanel implements MouseMotionListener, MouseListener
	{
		private Cegielka ceg [][];
		private Deska des;


		private Font czc;
		private boolean start;

		public BrickBreakerPanel(int xE, int yE)
		{
			ceg = zbudujCegielki(xE, yE);
			des = new Deska(xE, yE);


			czc = new Font("Verdana", Font.BOLD, 10);
			start = false;

			addMouseMotionListener(this);
			addMouseListener(this);
			setFont(czc);
		}

		public Cegielka [][] getC()
		{
			return ceg;
		}

		public Deska getD()
		{
			return des;
		}


		public Cegielka [][] zbudujCegielki(int xE, int yE)
		{
			Cegielka [][] c = new Cegielka [10][20];
			double ax = 0.005 * xE;
			double ay = 0.04 * yE;

			for (int i = 0; i < 10; i++)
			{
				for (int j = 0; j < 20; j++)
				{
					c[i][j] = new Cegielka();
					c[i][j].setX((int)(ax));
					c[i][j].setY((int)(ay));
					c[i][j].setW((int)(0.04 * xE));
					c[i][j].setH((int)(0.02 * yE));

					ax += 0.05 * xE;
				}

				ay += 0.03 * yE;
				ax = 0.005 * xE;
			}

			return c;
		}

		public void wyswietlCegielki(Graphics g)
		{
			for (int i = 0; i < ceg.length; i ++)
				for (int j = 0; j < ceg[i].length; j++)
					ceg[i][j].wyswietlCegielke(g);
		}

		public void wyswietlDeske(Graphics g)
		{
			des.wyswietlDeske(g);
		}




		public void paintComponent(Graphics g)
		{
			super.paintComponent(g);
			g.setColor(Color.red);
			wyswietlCegielki(g);
			g.setColor(Color.green);
			wyswietlDeske(g);

		}

		@Override
		public void mouseDragged(MouseEvent me) {
		}

		@Override
		public void mouseMoved(MouseEvent me) {
			des.setX(me.getX() - des.getW() / 2);

		}

		@Override
		public void mouseClicked(MouseEvent me) {
			start = true;
		}

		@Override
		public void mouseEntered(MouseEvent me) {
		}

		@Override
		public void mouseExited(MouseEvent me) {
		}

		@Override
		public void mousePressed(MouseEvent me) {
		}

		@Override
		public void mouseReleased(MouseEvent me) {
		}
	}

	@Override
	public void keyPressed(KeyEvent ke) {
		if (ke.getKeyCode() == KeyEvent.VK_ESCAPE)
			System.exit(0);
	}

	@Override
	public void keyReleased(KeyEvent ke) {
	}

	@Override
	public void keyTyped(KeyEvent ke) {
	}

	public BrickBreaker()
	{
		BrickBreakerPanel p = new BrickBreakerPanel(Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height);
		add(p);

		addKeyListener(this);
		requestFocus();

		setUndecorated(true);
		setResizable(false);

		przelaczNaPelnyEkran();
		ukryjKursorMyszy();

		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		new Wat(p);


	}


		public void przelaczNaPelnyEkran()
	{
		DisplayMode displayMode = new DisplayMode(Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height, 24, 75);
		GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
		GraphicsDevice device = environment.getDefaultScreenDevice();
		device.setFullScreenWindow(this);


		try
		{
			device.setDisplayMode(displayMode);
		}
		catch (IllegalArgumentException e)
		{
			System.out.println("Wyjatek!");
		}
	}



	public void ukryjKursorMyszy()
	{
		GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
		GraphicsDevice device = environment.getDefaultScreenDevice();

		Cursor invisibleCursor = Toolkit.getDefaultToolkit().createCustomCursor(Toolkit.getDefaultToolkit().getImage(""), new Point(0, 0), "invisible");
		device.getFullScreenWindow().setCursor(invisibleCursor);
	}

	public static void main(String[] args) {
		new BrickBreaker();
	}
}
